#!/bin/sh

#  postautomator.sh
#
#
#  Created by Nathan Taylor on 11/26/20.
#Drives
OS1=$(cd /Volumes; ls -1 | sed -n 1p)
OS2=$(cd /Volumes; ls -1 | sed -n 2p)
OS3=$(cd /Volumes; ls -1 | sed -n 3p)
OS4=$(cd /Volumes; ls -1 | sed -n 4p)
OS5=$(cd /Volumes; ls -1 | sed -n 5p)
OS6=$(cd /Volumes; ls -1 | sed -n 6p)

#What drive is macos on?
if defaults read /Volumes/"$OS1"/System/Library/CoreServices/SystemVersion ProductVersion | grep "11.*"; then
        if [ ! -x /Volumes/"$OS1"/Install\ macOS\ Big\ Sur.app ]; then
            echo "macOS 11 Detected! Continuing..."
            VOLUME=$(cd /Volumes; ls -1 | sed -n 1p)
        fi
fi


if defaults read /Volumes/"$OS2"/System/Library/CoreServices/SystemVersion ProductVersion | grep "11.*"; then
        if [ ! -x /Volumes/"$OS2"/"Install macOS Big Sur.app" ]; then
            echo macOS 11 Detected! Continuing...
            VOLUME=$(cd /Volumes; ls -1 | sed -n 2p)
        fi
fi

if defaults read /Volumes/"$OS3"/System/Library/CoreServices/SystemVersion ProductVersion | grep "11.*"; then
        if [ ! -x /Volumes/"$OS3"/"Install macOS Big Sur.app" ]; then
            echo macOS 11 Detected! Continuing...
            VOLUME=$(cd /Volumes; ls -1 | sed -n 3p)
        fi

fi

if defaults read /Volumes/"$OS4"/System/Library/CoreServices/SystemVersion ProductVersion | grep "11.*"; then
        if [ ! -x /Volumes/"$OS4"/"Install macOS Big Sur.app" ]; then
            echo macOS 11 Detected! Continuing...
            VOLUME=$(cd /Volumes; ls -1 | sed -n 4p)
        fi

fi

if defaults read /Volumes/"$OS5"/System/Library/CoreServices/SystemVersion ProductVersion | grep "11.*"; then
        if [ ! -x /Volumes/"$OS5"/"Install macOS Big Sur.app" ]; then
            echo macOS 11 Detected! Continuing...
            VOLUME=$(cd /Volumes; ls -1 | sed -n 5p)
        fi

fi

if defaults read /Volumes/"$OS6"/System/Library/CoreServices/SystemVersion ProductVersion | grep "11.*"; then
        if [ ! -x /Volumes/"$OS6"/"Install macOS Big Sur.app" ]; then
            echo macOS 11 Detected! Continuing...
            VOLUME=$(cd /Volumes; ls -1 | sed -n 6p)
        fi

fi

#not found at all

if ! defaults read /Volumes/"$VOLUME"/System/Library/CoreServices/SystemVersion ProductVersion | grep "11.*" ; then
    echo macOS 11 not found!
    exit
fi
#Model,OSVER
OSVER=$(defaults read /Volumes/"$VOLUME"/System/Library/CoreServices/SystemVersion ProductVersion)

Model=$(sysctl hw.model)

ModelIdentifier=$(echo $Model)

ReadModel=$(sysctl -n hw.model)

echo $ReadModelr running $OSVER detected!
#MacbookPros
if [ "$ModelIdentifier" = "hw.model: MacBookPro10,1" ]; then
    echo "Supported Mac Detected!"
    "/Volumes/Image Volume/patch-kexts.sh" "/Volumes/$VOLUME"
    exit
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro10,2" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro9,1" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro9,2" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi
#NoAccelMacBookPro
if [ "$ModelIdentifier" = "hw.model: MacBookPro5,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro5,5" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro5,4" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro5,3" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro5,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro7,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro6,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro6,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro8,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro8,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

if [ "$ModelIdentifier" = "hw.model: MacBookPro8,3" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

#Mac Mini
if [ "$ModelIdentifier" = "hw.model: MacMini6,1" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: MacMini6,2" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: MacMini3,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable."
     echo "Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacMini4,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     echo "Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacMini5,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     echo "Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

if [ "$ModelIdentifier" = "hw.model: MacMini5,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     echo "Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

if [ "$ModelIdentifier" = "hw.model: MacMini5,3" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     echo "Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

#Mac Pro
if [ "$ModelIdentifier" = "hw.model: MacPro3,1" ]; then
    echo "Please use BigMac Patcher! The BigMac Patcher is made for Mac Pros. This patcher will continue in 30 seconds if you do not want to use the BigMac Patcher."
    sleep 30
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" -2010
    exit
fi

if [ "$ModelIdentifier" = "hw.model: MacPro4,1" ]; then
        echo "Please use BigMac Patcher! The BigMac Patcher is made for Mac Pros. This patcher will continue in 30 seconds if you do not want to use the BigMac Patcher."
    sleep 30
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
    exit
fi

if [ "$ModelIdentifier" = "hw.model: MacPro5,1" ]; then
        echo "Please use BigMac Patcher! The BigMac Patcher is made for Mac Pros. This patcher will continue in 30 seconds if you do not want to use the BigMac Patcher."
    sleep 30
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
    exit
fi
#iMacs
if [ "$ModelIdentifier" = "hw.model: iMac9,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: iMac10,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: iMac11,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: iMac12,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

if [ "$ModelIdentifier" = "hw.model: iMac12,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

if [ "$ModelIdentifier" = "hw.model: iMac13,1" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: iMac13,2" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: iMac14,1" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: iMac14,2" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: iMac14,3" ]; then
    echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

#NoAccelMacBookAir
if [ "$ModelIdentifier" = "hw.model: MacBookAir2,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookAir3,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookAir3,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBookAir4,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

if [ "$ModelIdentifier" = "hw.model: MacBookAir4,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable.
     Please cancel this patcher and downgrade to Catalina or older.
    This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2011
fi

#MacBookAir
if [ "$ModelIdentifier" = "hw.model: MacBookAir5,1" ]; then
        echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

if [ "$ModelIdentifier" = "hw.model: MacBookAir5,2" ]; then
    echo echo "Supported Mac Detected!"
    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME"
fi

#NoAccelMacBook

if [ "$ModelIdentifier" = "hw.model: MacBook5,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBook5,2" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBook6,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi

if [ "$ModelIdentifier" = "hw.model: MacBook7,1" ]; then
    echo "This machine will not have graphics acceleration, and will therefore be nearly unusable. Please cancel this patcher and downgrade to Catalina or older. This patcher will continue in 30 seconds if you do not cancel."
    
    sleep 30

    /Volumes/Image\ Volume/patch-kexts.sh "/Volumes/$VOLUME" --2010
fi
